package com.mdb.open.trade.resource.trade;

/*
* Copyright (C), 2017-2019 澳发科技(MDB)
* FileName: TfTradeFileBasicInfoService.java
* Author:   you.yichao
* Date:     2019-08-08
* History:
* <author>          <time>          <version>          <desc>
* you.yichao         2019-08-08          V1.00        代码生成器初始生成代码
* -----------------------------------------------------------
* 作者姓名           修改时间           版本号            描述
*/


import com.google.common.collect.Lists;
import com.mdb.bc.api.data.ListResultEx;
import com.mdb.bc.api.enums.OrderByEnum;
import com.mdb.bc.logger.LogAnnotation;
import com.mdb.bc.utils.ObjectUtil;
import com.mdb.bc.web.support.SuperResources;
import com.mdb.open.trade.constant.trade.Fields;
import com.mdb.open.trade.domain.bo.trade.QueryTradeFilePageListBo;
import com.mdb.open.trade.domain.dto.trade.QueryTradeFilePageListDto;
import com.mdb.open.trade.domain.ko.trade.TradeFilePageListKo;
import com.mdb.open.trade.domain.vo.trade.TradeFilePageListVo;
import com.mdb.open.trade.service.trade.*;
import com.mdb.user.LoginUserInfoHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 类描述：
 *  融资档案资料表 前端控制器
 *
 * @author you.yichao
 * @date 2019-08-08
 */
@Api(tags = "融资档案")
@RestController
@RequestMapping("tf")
public class TradeFileTempResource extends SuperResources {


    @Autowired
    TfTradeFileBasicInfoService tfTradeFileBasicInfoService;

    @Autowired
    TfAttachFileService tfAttachFileService;

    @Autowired
    LoginUserInfoHelper loginUserInfoHelper;


    @LogAnnotation
    @ApiOperation("融资档案业务信息分页列表")
    @GetMapping("/trade/page_list")
    public ListResultEx<TradeFilePageListVo> applyPageQuery(@ModelAttribute QueryTradeFilePageListDto dto) {
        QueryTradeFilePageListBo bo = new QueryTradeFilePageListBo();
        bo.setBusinessNo(dto.getBusinessNo());
        bo.setMerchantName(dto.getMerchantName());
        bo.setStatus(dto.getStatus());
        bo.setApplyStatus(dto.getApplyStatus());
        bo.setCustomerCode(loginUserInfoHelper.getCustomerCode(true));
        bo.setStartDate(dto.getStartDate());
        bo.setEndDate(dto.getEndDate());
        bo.setPageNo(dto.getPageNo());
        bo.setPageSize(dto.getPageSize());
        bo.setSort(dto.getSort());
        bo.setOrder(dto.getOrder());
        if (ObjectUtil.isEmpty(dto.getSort())) {
            bo.setSort(Fields.ID);
            bo.setOrder(OrderByEnum.DESC);
        }

        ListResultEx<TradeFilePageListKo> pageListKoListResultEx = tfTradeFileBasicInfoService.applyPageQuery(bo);
        if (pageListKoListResultEx.isFailed()) {
            return ListResultEx.makeResult(pageListKoListResultEx.getRetCode(), pageListKoListResultEx.getRetMsg());
        }

        List<TradeFilePageListVo> voList = Lists.newArrayList();
        TradeFilePageListVo vo = null;
        for (TradeFilePageListKo ko : pageListKoListResultEx.getData()) {
            vo = new TradeFilePageListVo();
            vo.setTradeFileNo(ko.getTradeFileNo());
            vo.setCustomerCode(ko.getCustomerCode());
            vo.setCustomerName(ko.getCustomerName());
            vo.setMerchantNo(ko.getMerchantNo());
            vo.setMerchantName(ko.getMerchantName());
            vo.setBusinessNo(ko.getBusinessNo());
            vo.setApplyOrderNo(ko.getApplyOrderNo());
            vo.setStatus(ko.getStatus());
            vo.setApplyStatus(ko.getApplyStatus());
            vo.setCreateTime(ko.getCreateTime());
            vo.setUpdateTime(ko.getUpdateTime());
            voList.add(vo);
        }

        return ListResultEx.ok(voList, pageListKoListResultEx.getTotal(), pageListKoListResultEx.getPageNo(), pageListKoListResultEx.getPageSize());

    }


//    @LogAnnotation
//    @ApiOperation("上传出口核销单")
//    @PostMapping("/upload_export_file")
//    @DenyRepeatSubmit(type = RepeatSubmitTypeEnum.EXCLUSIVE_SUBMIT)
//    public ResultEx uploadExportFile(@RequestBody SaveAttachFileDto dto) {
//
//        ResultEx saveEx = tfAttachFileService.saveAttachFile(dto);
//        if (saveEx.isFailed()) {
//            return saveEx;
//        }
//
//        QueryAttachListByNoAndTypeListBo bo = new QueryAttachListByNoAndTypeListBo();
//        bo.setCustomerCode(dto.getCustomerCode());
//        bo.setApplyOrderNo(dto.getApplyOrderNo());
//        bo.setType(Lists.newArrayList(dto.getType()));
//        bo.setStatus(AttachFileStatusEnum.NORMAL);
//
//        int cnt = tfAttachFileService.cntAttachByNoAndType(bo);
//        TradeFileTempBasicInfoBo basicInfoBo = new TradeFileTempBasicInfoBo();
//        basicInfoBo.setTradeFileNo(dto.getApplyOrderNo());
//        basicInfoBo.setCustomerCode(dto.getCustomerCode());
//        basicInfoBo.setMerchantNo(dto.getMerchantNo());
//        if (webProperties.getTrade().getExportFileSize() <= cnt) {
//            basicInfoBo.setExportVeriStatus(LoanApplyExportFileStatusEnum.UPLOAD_COMPLETED);
//            ResultEx updateEx = tfTradeFileBasicInfoService.updateExportStatus(basicInfoBo);
//            if (updateEx.isFailed()) {
//                return updateEx;
//            }
//        } else {
//            basicInfoBo.setExportVeriStatus(LoanApplyExportFileStatusEnum.UPLOAD_PART);
//            ResultEx updateEx = tfTradeFileBasicInfoService.updateExportStatus(basicInfoBo);
//            if (updateEx.isFailed()) {
//                return updateEx;
//            }
//        }
//
//        return ResultEx.ok();
//    }



}
